#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "timer.h"
#include "debug_printf.h"

static void doSet(Timer *this, int i);
static void doStart(Timer *this);
static void doStep(Timer *this, int i);
static int doIsOver(Timer *this);

#define GOD_TIMER clock() / (CLOCKS_PER_SEC / 100)

Timer *makeTimer(timer_type t) {
	Timer *timer;

	if(t == DEFAULT) {
		timer = (Timer*) malloc(sizeof(Timer)*10);
		timer->set = doSet;
		timer->step = doStep;
		timer->start = doStart;
		timer->isOver = doIsOver;
		return timer;
	}
}

static void doTick(Timer *this) {


}

static void doStart(Timer *this) {
	// this->last = time(NULL);
	this->last = GOD_TIMER;
}

static void doSet(Timer *this, int i) {
	this->slice = i;
	this->count = 0;
	doStart(this);
}

static void doStep(Timer *this, int i) {


}

static int doIsOver(Timer *this) {
	clock_t atual = GOD_TIMER;	
	D("Atual %ld\n", atual);
	D("Last %ld\n", this->last);
	// if((atual - this->last) > this->slice) {
	if((atual - this->last) > this->slice) {
		this->last = GOD_TIMER;
		D("Rolando\n");
		return 1;
	}

	return 0;
}


